<?php
namespace app\controllers;

use app\models\SetRecorder;

class SetController extends BaseController{
    //添加
    public function actionAdd(){
        $post = \Yii::$app->request->post("form");
        $is_web = @file_get_contents('../data/install.lock');
        $is_web = intval($is_web);
        $post['pic_url'] = ($is_web)?$post['base_url']:$post['base_url']."web/";
        $model = SetRecorder::find()->where('set_id=1')->one();
        $model->set_info = json_encode($post);
        $model->save(false);
        $result = ['result'=>1,'data'=>'操作成功'];
        return json_encode($result);
    }

    //获取内容
    public function actionOne(){
        $model = SetRecorder::find()->where('set_id=1')->one();
        $arr = json_decode($model->set_info,true);
        $result = ['result'=>1,'data'=>$arr];
        return json_encode($result);
    }

    public function actionUrl(){
        $is_web = @file_get_contents('../data/install.lock');
        $is_web = intval($is_web);
        $url_dir = \Yii::$app->request->getBaseUrl();
        $url_dir = ($is_web)?$url_dir."/":str_replace("web","",$url_dir);
        $url = \Yii::$app->request->getHostInfo();
        $url.=$url_dir;
        $result = ['result'=>1,'data'=>$url];
        return json_encode($result);
    }

}
